/*******************************************************************************
 * This file is part of blueprint4j www.blueprint4j.org.
 * 
 *     blueprint4j is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Lesser General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     blueprint4j is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Lesser General Public License for more details.
 * 
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with blueprint4j. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package blueprint4j.gui;

import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.plaf.metal.*;

class SingleColorTheme extends DefaultMetalTheme {
	private final ColorUIResource highlight_darker;
	private final ColorUIResource highlight_middle;
	private final ColorUIResource highlight_lighter;
	private final ColorUIResource color_darker;
	private final ColorUIResource color_middle;
	private final ColorUIResource color_lighter;
	private float factor;

	public SingleColorTheme(Color color) {
		this(color, 0.3f);
	}

	public SingleColorTheme(Color color, float p_factor) {
		// Set factor
		factor = p_factor;
		// Set color
		int r = color.getRed(), g = color.getGreen(), b = color.getBlue();
		color_darker =
			new ColorUIResource(
				(int)(r * (1f - factor)),
				(int)(g * (1f - factor)),
				(int)(b * (1f - factor))
			);
		color_middle = new ColorUIResource(r, g, b);
		color_lighter =
			new ColorUIResource(
				(int)((r * (1f + factor) > 255) ? 255 : (r * (1f + factor))),
				(int)((g * (1f + factor) > 255) ? 255 : (g * (1f + factor))),
				(int)((b * (1f + factor) > 255) ? 255 : (b * (1f + factor)))
			);
		// Highlights
		r /= 2;
		g /= 2;
		b /= 2;
		highlight_darker =
			new ColorUIResource(
				(int)(r * (1f - factor)),
				(int)(g * (1f - factor)),
				(int)(b * (1f - factor))
			);
		highlight_middle = new ColorUIResource(r, g, b);
		highlight_lighter =
			new ColorUIResource(
				(int)((r * (1f + factor) > 255) ? 255 : (r * (1f + factor))),
				(int)((g * (1f + factor) > 255) ? 255 : (g * (1f + factor))),
				(int)((b * (1f + factor) > 255) ? 255 : (b * (1f + factor)))
			);
	}

	protected ColorUIResource getPrimary1() {
		return color_darker;
	}

	protected ColorUIResource getPrimary2() {
		return color_middle;
	}

	protected ColorUIResource getPrimary3() {
		return color_lighter;
	}

	protected ColorUIResource getSecondary1() {
		return color_darker;
	}

	protected ColorUIResource getSecondary2() {
		return color_middle;
	}

	protected ColorUIResource getSecondary3() {
		return color_lighter;
	}
}

